package com.bayi.storage.base

import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import android.util.AttributeSet
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.bayi.storage.utils.ToastUtil
import com.bayi.storage.utils.Utils
import com.lky.toucheffectsmodule.factory.TouchEffectsFactory
import java.lang.reflect.ParameterizedType

/**
 * @author Administrator on 2024-05-31.
 * <p>
 * 站在顶峰 看世界
 * 落到谷底 思人生
 */
abstract class BaseFragment<VM : BaseViewModel, VB : ViewDataBinding> : Fragment() {

    lateinit var binding: VB

    lateinit var mViewModel: VM

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = createViewBinding()
        binding.lifecycleOwner = this
        //获得泛型参数的实际类型
        val vmClass =
            (this.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<VM>
        mViewModel = ViewModelProvider(this).get(vmClass)
        initView()
        return binding.root
    }

    protected abstract fun createViewModel(): VM
    protected abstract fun createViewBinding(): VB
    protected abstract fun initView()

}